package com.geofitti.andoird;

import java.io.File;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.widget.ImageView;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class ItemizedOverlays extends ItemizedOverlay {
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private ArrayList<String> mOverlaysImages = new ArrayList<String>();
	Context mContext;
	String classdbImage;
	
	public ItemizedOverlays(Drawable defaultMarker) {
		super(boundCenterBottom(defaultMarker));
		try {
			JSONObject jsonO = WebCall.doGet("http://icarus.cs.weber.edu/~km06559/geofitti.php/getImage");
			classdbImage = jsonO.getString("photo");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// TODO Auto-generated constructor stub
	}
	

	public void addOverlay(OverlayItem overlay, String theStr){
		mOverlays.add(overlay);
		mOverlaysImages.add(theStr);
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int i){
		return mOverlays.get(i);
	}
	
	@Override
	public int size(){
		return mOverlays.size();
	}
	
	public ItemizedOverlays(Drawable defaultMarker, Context context){
		super (boundCenterBottom(defaultMarker));
		mContext = context;
	}
	
	@Override
	protected boolean onTap(int index) {
      OverlayItem item = mOverlays.get(index);
//     String thephotostr = mOverlaysImages.get(index);
      

      
      JSONObject jsonO;
      if(item.getTitle() == "todizzle"){
          Intent i = new Intent(mContext, PictureView.class);
	      try { 
	          jsonO = WebCall.doGet("http://icarus.cs.weber.edu/~km06559/geofitti.php/getImage");
	          i.putExtra("dbImage", jsonO.getString("photo"));
	
	      } catch (JSONException e) {
	          // TODO Auto-generated catch block
	          e.printStackTrace();
	      }
	      mContext.startActivity(i);
      }else if(item.getTitle() == "slcc"){
    		  Intent i = new Intent(mContext, PictureView2.class);
    	      mContext.startActivity(i);
      }else if(item.getTitle() == "uofu"){
		  Intent i = new Intent(mContext, PictureView3.class);
	      mContext.startActivity(i);
      }else if(item.getTitle() == "weber"){
		  Intent i = new Intent(mContext, PictureView4.class);
	      mContext.startActivity(i);
      }else if(item.getTitle() == "fireworks"){
		  Intent i = new Intent(mContext, PictureView5.class);
	      mContext.startActivity(i);
      }else if(item.getTitle() == "booth"){
		  Intent i = new Intent(mContext, PictureView6.class);
	      mContext.startActivity(i);
      }else if(item.getTitle() == "sunset"){
		  Intent i = new Intent(mContext, PictureView7.class);
	      mContext.startActivity(i);
      }else if(item.getTitle() == "weber"){
		  Intent i = new Intent(mContext, PictureView4.class);
	      mContext.startActivity(i);
      }
      

      return true;
	}
	 
	public void setImage(Bitmap dbImage){
	//	this.thePictureView.setImage(dbImage);
		return;
	}
}
